package com.bisp30;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class MyCollectionList extends ListActivity {

	 /*	 private ListView CollectionList;
	 List<String> data;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		TextView bookListCon = new TextView(this);
		bookListCon.setText("我的收藏");
		setContentView(bookListCon);
		
		CollectionList = new ListView(this);
		CollectionList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1,getData()));
		CollectionList.setItemsCanFocus(true);
		CollectionList.setOnItemClickListener(new OnItemClickListener(){
			@Override
			public void onItemClick(AdapterView<?> arg0, View v, int position, long id) {
				// TODO Auto-generated method stub
				Log.v("MyListView4-click", data.get(position).toString());
				 Intent intent = new Intent();
                 intent.setClass(MyCollectionList.this, BookReader.class);
                 startActivity(intent);
				
			}
        	
        });
        setContentView(CollectionList);
        
	}
	
	
	
	  private List<String> getData(){        
	        
		  	data = new ArrayList<String>();
			data.add("我的收藏1");
			data.add("我的收藏2");
			data.add("我的收藏3");
			data.add("我的收藏4");
			data.add("我的收藏5");
			data.add("我的收藏6");
			data.add("我的收藏7");
			data.add("我的收藏8");
			return data;
	
	    }*/
	
	 private List<Map<String, Object>> mData;
     
	    @Override
	    public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        mData = getData();
	        MyAdapter adapter = new MyAdapter(this);
	        setListAdapter(adapter);
	    }
	 
	    private List<Map<String, Object>> getData() {
	        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
	 
	        Map<String, Object> map = new HashMap<String, Object>();
	        map.put("title", "G1");
	        map.put("info", "google 1");
	        map.put("img", R.drawable.gear_blue);
	        list.add(map);
	 
	        map = new HashMap<String, Object>();
	        map.put("title", "G2");
	        map.put("info", "google 2");
	        map.put("img", R.drawable.gear_blue);
	        list.add(map);
	 
	        map = new HashMap<String, Object>();
	        map.put("title", "G3");
	        map.put("info", "google 3");
	        map.put("img", R.drawable.gear_blue);
	        list.add(map);
	        
	        return list;
	    }
	     
	    @Override
		protected void onListItemClick(ListView l, View v, int position, long id) {
			// TODO Auto-generated method stub
			super.onListItemClick(l, v, position, id);
			Log.v("MyListView4-click", (String)mData.get(position).get("title"));
			showInfo();
			
			//Intent intent = new Intent();
			//intent.setClass(MyCollectionList.this, BookReader.class);
			//startActivity(intent);
		}
	    // listview中点击按键弹出对话框
		public void showInfo(){
	        new AlertDialog.Builder(this)
	        .setTitle("我的listview")
	        .setMessage("介绍...")
	        .setPositiveButton("确定", new DialogInterface.OnClickListener() {
	            @Override
	            public void onClick(DialogInterface dialog, int which) {
	            	
	            }
	        })
	        .show();
	         
	    }
	     

		public final class ViewHolder{
	        public ImageView img;
	        public TextView title;
	        public TextView info;
	        //public Button viewBtn;
	    }
	     
	    public class MyAdapter extends BaseAdapter{
	 
	        private LayoutInflater mInflater;
	         
	        public MyAdapter(Context context){
	            this.mInflater = LayoutInflater.from(context);
	        }
	        @Override
	        public int getCount() {
	            // TODO Auto-generated method stub
	            return mData.size();
	        }
	 
	        @Override
	        public Object getItem(int arg0) {
	            // TODO Auto-generated method stub
	            return null;
	        }
	 
	        @Override
	        public long getItemId(int arg0) {
	            // TODO Auto-generated method stub
	            return 0;
	        }
	        
	        public View getView(int position, View convertView, ViewGroup parent) {
	             
	            ViewHolder holder = null;
	            if (convertView == null) {
	                 
	                holder=new ViewHolder();  
	                 
	                convertView = mInflater.inflate(R.layout.booklist, null);
	                holder.img = (ImageView)convertView.findViewById(R.id.img);
	                holder.title = (TextView)convertView.findViewById(R.id.title);
	                holder.info = (TextView)convertView.findViewById(R.id.info);
	                //holder.viewBtn = (Button)convertView.findViewById(R.id.view_btn);
	                convertView.setTag(holder);
	                 
	            }else {
	                 
	                holder = (ViewHolder)convertView.getTag();
	            }
	             
	            holder.img.setBackgroundResource((Integer)mData.get(position).get("img"));
	            holder.title.setText((String)mData.get(position).get("title"));
	            holder.info.setText((String)mData.get(position).get("info"));
	             
				return convertView;
	        }
	         
	    }

	    
}
